<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>订单</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="./js/jquery-1.11.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/main.js"></script>
    <style type="text/css">
        body {
            background: #2fb9e2;
        }
        
        .content {
            margin: auto;
            margin-top: 100px;
            padding: 5%;
            padding-top: 2%;
            width: auto;
            min-width: 1000px;
            height: auto;
            background-color: #fff;
            border-radius: 20px;
            box-shadow: 0px 0px 20px #5b7884;
        }
        
        .table {
            text-align: center;
            margin: auto;
            padding-bottom: 10px;
        }
        .btn {
            margin-left: 10px;
        }
        #add {
            float: right;
        }
        
        #order {
            float: right;
            margin-right: 15px;
        }
        
        #title {
            margin: auto;
            padding-top: 5px;
            padding-bottom: 5px;
        }
        
        .center {
            text-align: center;
        }
        .modal-body {
            padding-left: 50px;
            padding-right: 50px;
        }
    </style>

</head>
    <script>
        if (!getCookie('sessionid')){
            alert("没有登录")
            window.location.href = "login.html"
        }
    var current_page;
   
    $(document).ready(function() {
        getList(1)

        var colTr = '<tr><td colspan="1">姓名</td><td colspan="4">地址</td><td colspan="2">操作</td></tr> ';
        var contentTr;
        var i = 0;
        while (i<10){
            contentTr += addRow(i,"大妈" + i, "地址");
            i++;
        }
        var tableTr = colTr + contentTr;
        //$("#content_table").html(tableTr);

        $("#order").click(function(){
            //alert("order");
            direct_dama();
        })

        $("#prev").click(function () {
            if (current_page==0) {
                alert("已经是最后一页")
            }else{
                prev_page()
            }
        })

        $("#next").click(function () {
            next_page()
        })
    })
    function addRow(oid,dish,origin_price,price,datetime,status){
        var contentTr = '<tr id="tr_' + oid + '">';
        contentTr += '<td>'+ oid+'</td>';
        contentTr += '<td>'+ origin_price +'</td>';
        contentTr += '<td>'+ price +'</td>';
        contentTr += '<td>'+ datetime +'</td>';
        contentTr += '<td>'+ getStatusString(status) +'</td>';
        contentTr + '</tr>';
        return contentTr;
    }

    function getList(page){
        var session = getCookie('sessionid');
        //访问网络
        var settings = {
                type: "POST",
                url: "../../Fanxiangle/servlet/manager",
                dataType: "json",
                data: {
                    module: "order",
                    action: "getOrderList",
                    page: page,
                    sessionid: session
                },
                error: function(XHR, textStatus, errorThrown) {
                    alert("网络错误");
                },
                success: function(data, textStatus) {
                    if (textStatus == "success") {
                        if (data.status == true) {
                            //alert("data:" + data.data);
                            var colTr = '<tr><td>菜品</td><td>订单总价</td><td>订单原价</td><td>下单时间</td><td>当前状态</td></tr> ';
                            var contentTr;
                            $.each(data.data,function(index,value){
                                contentTr += addRow(value.oid,value.price, value.original_price, value.datetime,value.status);
                            })
                            var tableTr = colTr + contentTr;
                            $("#content_table").html(tableTr);
                            
                        } else if (data.errorCode == 1001) {
                            alert("参数不全")
                        } else if (data.errorCode == 1010) {
                            alert("数据库错误")
                        }  else if (data.errorCode == 1000) {
                            alert("未知错误")
                        }
                        //alert("data:" + data.data + ",status:" + textStatus)
                    }else{
                        alert("服务器错误");
                    }

                }
            };
            $.ajax(settings);
    }

    function direct_dama(){
        window.location.href = "manage.html"
    }
   
    function next_page () {
        current_page++;
        getList(current_page)
    }

    function prev_page () {
        current_page--;
        getList(current_page);
    }
        
        
</script>

<body>
    <!-- /.modal -->
    <div class="container">
        <div class="content">
            <h1 class="text-center">饭享乐-订单管理中心</h1>
            <div class="panel panel-info">

                <div class="panel-heading">
                    <button class="btn btn-sm btn-primary" id="order">切换大妈列表</button>
                    <p id="title"> <strong>订单列表</strong>
                    </p>
                </div>

                <div class="list-group">

                    <table class="table table-striped" id="content_table">
                        
                    </table>
                </div>

            </div>

            <nav class="center">
                <ul class="pager">
                    <li>
                        <a aria-label="Previous" id="prev">
                            <span aria-hidden="true">上一页</span>
                        </a>
                    </li>
                    <li>
                        <a aria-label="Next" id="next">
                            <span aria-hidden="true">下一页</span>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</body>

</html>